import java.text.{DateFormat, SimpleDateFormat}
import java.util.Date

import org.apache.hadoop.hbase.{HBaseConfiguration, HColumnDescriptor, HTableDescriptor, TableName}
import org.apache.hadoop.hbase.client.{Admin, ConnectionFactory, Table}
import org.apache.hadoop.hbase.util.Bytes

object Utils {
  def converDateFormat(inFormat:String,outFormat:String,inDatastr:String)={
    val dfIn:DateFormat = new SimpleDateFormat(inFormat)
    val date: Date = dfIn.parse(inDatastr)
    val dfOut:DateFormat = new SimpleDateFormat(outFormat)
    dfOut.format(date)
  }
  val conf = HBaseConfiguration.create()
  conf.set("hbase.zookeeper.quorum", "mini:2181")
  val conn = ConnectionFactory.createConnection(conf)
  def getConnect() = conn

   def createTable(tableName:String): Unit ={
    val admin: Admin = getConnect().getAdmin
    val htd: HTableDescriptor = new HTableDescriptor(TableName.valueOf(tableName))
    val hcd: HColumnDescriptor = new HColumnDescriptor(Bytes.toBytes("f1"))
    htd.addFamily(hcd)
    admin.createTable(htd)
  }
//获得表
  def getTable(tableName: String): Table ={
    val con = getConnect()
    val table: Table = getConnect().getTable(TableName.valueOf(tableName))
    table
  }
}
